public class StudentNumberLogic{
    
    public static  String getCheckDigitString( String pStudentID )
    {
        
        if (pStudentID != null)
        {
            List<Integer> sMatricula = new List<Integer>();
            List<Integer> aOperacion = new List<Integer>();
            Integer[] aMultiplicar = new Integer[]{17,13,11,23,19,17,13};
           // var Matricula =  StudentID;
            Integer x, y=0;
            
            Integer  sum = 0;
            for(Integer i=0;i<pstudentid.length();i++)
            {
               system.debug('------------->> '+ pstudentid.substring(i,i+1));
                sMatricula.add(Integer.valueof(pstudentid.substring(i,i+1).trim()));
            }             
            
            for(x=7; x >= 1; x--)
            { 
                aOperacion.add(sMatricula[7-x] * aMultiplicar[y]);
                sum= sum + aOperacion[7-x];
                y++;
            }
            sum = sum + 330;
            Integer module =(math.mod(sum, 97))+1;
            
            String result=String.valueOf(module);
                
            if (module<=9)
            {
                result = '0' + result ;
            } 
            
            return result;
        }
        return null;
    }// End of function
}